<?php

namespace App\Models;

use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;
#报告信息表模型
class Report_info extends Model
{
	#主键
	public $primaryKey='rid';

	public static function init($rid){
		$report_info=new Report_info;
		$report_info->rid=$rid;
		$report_info->save();
		return $report_info;
	}
	#修改报告信息
    public static function store(Request $request){
    	$rid=$request->input('rid');
    	$report_type=$request->input('report_type');
    	$report_info=Report_info::find($rid);
    	if(empty($report_info))
    		Report_info::init($rid);
    	#附件信息
		$report_info->attachmentname=" ";
		$report_info->attachmentpath=" ";

		switch ($report_type) {
			case 0:
				$report_info->选题背景=$request->input('选题背景');
				$report_info->解决途径=$request->input('解决途径');
				break;
			case 1:
				$report_info->所遇问题=$request->input('所遇问题');
				$report_info->后期计划=$request->input('后期计划');
				break;
			case 2:
				$report_info->研究成果=$request->input('研究成果');
				break;
			case 3:
				$report_info->成果跟踪=$request->input('成果跟踪');
				break;
			case 4:
				$report_info->展板提交=$request->input('展板提交');
				break;
			default:
				break;
		}
		$report_info->save();
    }
    #存储附件
    public static function storeAttach($rid,$name,$path){
    	$report_info=Report_info::find($rid);
    	    	#附件信息
		$report_info->attachmentname=$name;
		$report_info->attachmentpath=$path;
		$report_info->save();
    }

    public static function commit(Request $request,$rid){
		$report_info=Report_info::find($rid);
		$report_info->教师评语=$request->input('教师评语');
		$report_info->save();
    } 
}
